﻿define(['app'], function (app) {
    app.lazy.controller("ManageTagsController", ["$rootScope", "$scope", "$http", "localize", function ($rootScope, $scope, $http, localize) {
        $rootScope.title = "Manage Tags";

        $http.get("/dashboard/services/tags/getnames").success(function (data) {
            var tags = [];
            angular.forEach(data, function (tagName) {
                tags.push({
                    name: tagName,
                    checked: false
                });
            });
            $scope.tags = tags;
        });
        
        $scope.remove = function (index) {
            if ($scope.tags && $scope.tags.length > index) {
                $scope.tags.splice(index, 1);
            }
        };
        
        $scope.deleteSelected = function () {
            var i = $scope.tags.length - 1;

            while (i >= 0) {
                var tag = $scope.tags[i];
                
                if (tag.checked) $scope.tags.splice(i, 1);
                i--;
            }
        };
    }]);
});